import React, {useEffect, useState} from 'react';
import {
  ScrollView,
  View,
  Text,
  TouchableOpacity,
  ActivityIndicator,
  FlatList,
  Image,
  TextInput,
} from 'react-native';
import BaseUrl from '../../config/BaseUrl';
import {custList} from '../../service/home';
import {useNavigation} from '@react-navigation/native';
import AreaView from '../../components/Layout/AreaView';
import Score from '../../utils/Score';
import styles from './style';

let reg = /<\/?.+?\/?>/g;

const StarTeacher = () => {
  const navigation = useNavigation();
  const [teacherList, setTeacherList] = useState([]);

  useEffect(() => {
    // 明星老师
    custList({custType: 'T'}).then((res) => {
      console.log(res);
      setTeacherList(res.rows);
    });
  }, [navigation]);
  return (
    <AreaView>
      <ScrollView style={styles.container}>
        {(teacherList || []).map((item) => (
          <TouchableOpacity
            style={styles.list}
            key={item.custId}
            onPress={() =>
              navigation.push('StarTeacherDetail', {
                custId: item.custId,
              })
            }>
            <Image
              style={styles.cover}
              source={{uri: BaseUrl.imgurl + item?.image}}
            />
            <View style={styles.content}>
              <Text style={styles.name}>{item?.nickName}</Text>
              <View style={styles.star}>
                {Score(item.teacherLevel)?.map((s) => (
                  <Image style={styles.icon} source={s} />
                ))}
              </View>
              <Text style={styles.desc} numberOfLines={3}>
                <Text style={styles.desc_mark}>简介文字：</Text>
                {item?.custDesc?.replace(reg, '')}
              </Text>
            </View>
          </TouchableOpacity>
        ))}
      </ScrollView>
    </AreaView>
  );
};

export default StarTeacher;
